var t = require("../../../@babel/runtime/helpers/objectSpread2"), a = require("../../../@babel/runtime/helpers/defineProperty"), e = getApp();

Component({
    properties: {
        datas: {
            type: null
        },
        component_id: {
            type: null
        },
        page_id: {
            type: null
        },
        bottomShowBolIndex: {
            type: null
        },
        index: {
            type: null
        },
        U_tabcontrol: {
            type: null
        },
        bottomShowBol: {
            type: null
        },
        isLast: {
            type: null
        },
        plugin_active: {
            type: null
        },
        store_alone_temp: {
            type: null
        },
        store_id: {
            type: null
        },
        btnFlag: {
            type: null
        }
    },
    data: {
        emptyImage: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/image.png",
        clientWidth: "375",
        list: [],
        language: "",
        page: 1,
        total_page: 0,
        isLoadMore: !0,
        allLoaded: !1,
        active: 0,
        show_page: !0,
        nowTimes: new Date().getTime(),
        _arr: []
    },
    lifetimes: {
        attached: function() {
            var t = wx.getStorageSync("langIndex");
            this.setData({
                language: t.en
            });
        },
        moved: function() {},
        detached: function() {}
    },
    attached: function() {},
    ready: function() {
        this.data.datas.list && (this.setData({
            total_page: this.data.datas.list.last_page,
            page: this.data.datas.list.current_page,
            per_page: this.data.datas.list.per_page,
            list: this.data.datas.list.data && this.data.datas.list.data.slice(0, this.data.per_page) || [],
            tabData: this.data.datas.tablist || [],
            currentTime: parseInt(new Date().getTime() / 1e3)
        }), (this.data.total_page <= this.data.page || "2" == this.data.datas.style_set) && this.setData({
            isLoadMore: !1,
            allLoaded: !0
        })), this.setTime(), this.data.datas.get_number && this.data.datas.get_number <= this.data.per_page && this.setData({
            isLoadMore: !1,
            allLoaded: !0,
            list: this.data.datas.list.data.slice(0, this.data.datas.get_number)
        }), this.setData({
            clientWidth: wx.getSystemInfoSync().windowWidth
        });
    },
    pageLifetimes: {
        show: function() {},
        hide: function() {},
        resize: function() {}
    },
    methods: {
        setTime: function() {
            for (var t = new Date().getTime(), e = 0; e < this.data.list.length; e++) if (this.data.list[e].start_time) {
                var s, i = 1e3 * this.data.list[e].start_time;
                this.setData((a(s = {}, "list[" + e + "].day", "00"), a(s, "list[" + e + "].hou", "00"), 
                a(s, "list[" + e + "].min", "00"), a(s, "list[" + e + "].sec", "00"), s)), t > i ? (this._countDown(e, this.data.list[e].end_time), 
                this.setData(a({}, "list[" + e + "].begShow", !0))) : (this._countDown(e, this.data.list[e].start_time), 
                this.setData(a({}, "list[" + e + "].begShow", !1)));
            }
        },
        _countDown: function(t, e) {
            var s, i = new Date().getTime(), d = e ? 1e3 * e : 0;
            if (d - i > 0) {
                var o, n = (d - i) / 1e3, l = parseInt(n / 86400), r = parseInt(n % 86400 / 3600), g = parseInt(n % 86400 % 3600 / 60), p = parseInt(n % 86400 % 3600 % 60);
                this.setData((a(o = {}, "list[" + t + "].day", this._timeFormat(l)), a(o, "list[" + t + "].hou", this._timeFormat(r)), 
                a(o, "list[" + t + "].min", this._timeFormat(g)), a(o, "list[" + t + "].sec", this._timeFormat(p)), 
                o));
            } else {
                var h;
                this.setData((a(h = {}, "list[" + t + "].day", "00"), a(h, "list[" + t + "].hou", "00"), 
                a(h, "list[" + t + "].min", "00"), a(h, "list[" + t + "].sec", "00"), h));
            }
            d - i < 0 ? this.setData((a(s = {}, "list[" + t + "].day", "00"), a(s, "list[" + t + "].hou", "00"), 
            a(s, "list[" + t + "].min", "00"), a(s, "list[" + t + "].sec", "00"), s)) : setTimeout(this._countDown.bind(this, t, e), 1e3);
        },
        _timeFormat: function(t) {
            return t < 10 ? "0" + t : t;
        },
        gotoDetail: function(t) {
            var a = t.currentTarget.dataset.item.id;
            78 == t.currentTarget.dataset.item.plugin_id ? wx.navigateTo({
                url: "/packageA/detail_v2/detail_v2?id=" + a + "&md=1"
            }) : wx.navigateTo({
                url: "/packageA/detail_v2/detail_v2?id=" + a
            });
        },
        getMoreData: function() {
            var t = this, a = this;
            if (this.data.page >= this.data.total_page) this.setData({
                allLoaded: !0
            }); else {
                a.setData({
                    page: a.data.page + 1
                });
                var s = e.getNetAddresss("home-page.get-decorate-page");
                this.properties.store_id && (s += "&store_id=".concat(this.properties.store_id)), 
                s += "&page=" + a.data.page, s += "&decorate_id=" + a.data.page_id, s += "&component_id=" + a.data.component_id, 
                this.data.U_tabcontrol ? (s += "&component_key=U_tabcontrol", s += "&component_info=" + JSON.stringify({
                    list_key: this.data.index
                })) : s += "&component_key=U_goodsrush", e._getNetWork({
                    url: s,
                    success: function(e) {
                        var s = e.data;
                        if (1 == s.result) {
                            if (t.data.U_tabcontrol ? a.setData({
                                page: s.data[0].remote_data.list.current_page,
                                list: t.data.list.concat(s.data[0].remote_data.list.data)
                            }) : a.setData({
                                page: s.data.current_page,
                                list: t.data.list.concat(s.data.data)
                            }), t.setTime(), !(a.data.page < a.data.total_page)) return void a.setData({
                                allLoaded: !0
                            });
                            a.setData({
                                isLoadMore: !0
                            }), t.data.datas.get_number && t.data.list.length > t.data.datas.get_number && t.setData({
                                isLoadMore: !1,
                                allLoaded: !0,
                                list: t.data.list.slice(0, t.data.datas.get_number)
                            });
                        } else a.setData({
                            page: a.data.page - 1,
                            isLoadMore: !1,
                            allLoaded: !0
                        });
                    },
                    fail: function(t) {}
                });
            }
        },
        loadMoreMemberData: function() {
            var t = this, a = this;
            if (a.setData({
                isLoadMore: !1
            }), !(a.data.datas.current_page >= a.data.datas.last_page)) {
                a.data.datas.current_page += 1;
                var s = e.getNetAddresss("member.member.plugin-data");
                1 == this.data.store_alone_temp && (s = e.getNetAddresss("plugin.store-alone-temp.frontend.member.nav-data")), 
                s += "&page=" + a.data.datas.current_page, s += "&code=" + a.data.plugin_active, 
                e._getNetWork({
                    url: s,
                    success: function(e) {
                        var s = e.data;
                        1 == s.result ? (a.setData({
                            list: t.data.list.concat(s.data.data.data)
                        }), t.setTime(), a.data.datas.current_page < a.data.datas.last_page ? a.setData({
                            isLoadMore: !0
                        }) : a.setData({
                            allLoaded: !0
                        }), a.triggerEvent("setLoadMore", {
                            isLoadMore: a.data.isLoadMore
                        })) : a.setData({
                            page: a.data.datas.current_page - 1,
                            isLoadMore: !1,
                            allLoaded: !0
                        });
                    },
                    fail: function(t) {
                        console.log(t);
                    }
                });
            }
        },
        onChangeTabs: function(t) {
            this.setData({
                active: t.detail.name,
                _arr: []
            });
        },
        onChangeCountDown: function(a) {
            this.data._arr[a.target.dataset.id] = t(t({}, a.detail), {}, {
                id: a.target.dataset.id
            }), this.setData({
                timeData: this.data._arr
            });
        }
    },
    observers: {
        bottomShowBol: function(t) {
            t && this.data.bottomShowBolIndex == this.data.index && 5 != this.data.datas.sort_style.choose_icon && this.data.isLoadMore && this.getMoreData();
        }
    }
});